<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	template="/templates/communication/decorator.xhtml">

	<ui:define name="titulo">
		<h:outputText value="#{msg.listar} #{msg.sorteios}" />
	</ui:define>

	<ui:define name="alertas">
		<h:form id="alertas">
			<h:outputText value="${sorteioFace.errorMessages}" />
			<h:messages showDetail="#{true}" showSummary="#{false}" />
		</h:form>
	</ui:define>

	<ui:define name="mensagens">
		<h:outputText value="${sorteioFace.resultado}" />
	</ui:define>

	<ui:define name="conteudo">
		<div class="post">
		<div class="post-bgtop">
		<div class="post-bgbtm"><h:form id="formulario">
			<h:inputHidden id="id" value="#{sorteioFace.pojoSelecionado.id}" />
			<h2 class="title"><h:outputText
				value="#{msg.cadastrar} #{msg.sorteio}"
				rendered="#{empty sorteioFace.pojoSelecionado.id}" /> <h:outputText
				value="#{msg.alterar} #{msg.sorteio}"
				rendered="#{!empty sorteioFace.pojoSelecionado.id}" /></h2>

			<h:panelGrid columns="3" cellpadding="5" border="1">

				<h:outputText value="Concurso: " />
				<h:inputText id="concurso" label="Campo Concurso"
					value="#{sorteioFace.pojoSelecionado.concurso}" required="false"
					requiredMessage="#{msg.INPUT_REQUIRED}" immediate="true" />
				<h:message id="avisoConcurso" for="concurso" styleClass="AVISO" />

				<h:outputText value="Data Sorteio: " />
				<h:inputText id="dataSorteio" label="Campo Data Sorteio"
					value="#{sorteioFace.pojoSelecionado.dataSorteio}"
					requiredMessage="#{msg.INPUT_REQUIRED}" styleClass="text data"
					required="true">
					<f:convertDateTime pattern="dd/MM/yyyy" />
				</h:inputText>
				<h:message id="avisoDataSorteio" for="dataSorteio"
					styleClass="AVISO" />

				<h:panelGrid columns="4" border="1" cellpadding="5" rules="all" title="Dezenas">
					<h:outputText value="1 Dezena: " />
					<h:inputText id="primeiraDezena" label="Campo 1 Dezena"
						maxlength="2" size="2"
						value="#{sorteioFace.pojoSelecionado.primeiraDezena}"
						required="false" requiredMessage="#{msg.INPUT_REQUIRED}"
						immediate="true" />
					<h:message id="avisoPrimeiraDezena" for="primeiraDezena"
						styleClass="AVISO" />

					<h:outputText value="2 Dezena: " />
					<h:inputText id="segundaDezena" label="Campo 2 Dezena"
						maxlength="2" size="2"
						value="#{sorteioFace.pojoSelecionado.segundaDezena}"
						required="false" requiredMessage="#{msg.INPUT_REQUIRED}"
						immediate="true" />
					<h:message id="avisoSegundaDezena" for="segundaDezena"
						styleClass="AVISO" />

					<h:outputText value="3 Dezena: " />
					<h:inputText id="terceiraDezena" label="Campo 3 Dezena"
						maxlength="2" size="2"
						value="#{sorteioFace.pojoSelecionado.terceiraDezena}"
						required="false" requiredMessage="#{msg.INPUT_REQUIRED}"
						immediate="true" />
					<h:message id="avisoTerceiraDezena" for="terceiraDezena"
						styleClass="AVISO" />

					<h:outputText value="4 Dezena: " />
					<h:inputText id="quartaDezena" label="Campo 4 Dezena" maxlength="2"
						size="2" value="#{sorteioFace.pojoSelecionado.quartaDezena}"
						required="false" requiredMessage="#{msg.INPUT_REQUIRED}"
						immediate="true" />
					<h:message id="avisoQuartaDezena" for="quartaDezena"
						styleClass="AVISO" />

					<h:outputText value="5 Dezena: " />
					<h:inputText id="quintaDezena" label="Campo 5 Dezena" maxlength="2"
						size="2" value="#{sorteioFace.pojoSelecionado.quintaDezena}"
						required="false" requiredMessage="#{msg.INPUT_REQUIRED}"
						immediate="true" />
					<h:message id="avisoQuintaDezena" for="quintaDezena"
						styleClass="AVISO" />

					<h:outputText value="6 Dezena: " />
					<h:inputText id="sextaDezena" label="Campo 6 Dezena" maxlength="2"
						size="2" value="#{sorteioFace.pojoSelecionado.sextaDezena}"
						required="false" requiredMessage="#{msg.INPUT_REQUIRED}"
						immediate="true" />
					<h:message id="avisoSextaDezena" for="sextaDezena"
						styleClass="AVISO" />
				</h:panelGrid>
				<h:outputText value="" />
				<h:outputText value="" />

				<h:outputText value="Acumulado?" />
				<h:selectOneRadio id="acumulado" border="1" layout="pageDirection"
					value="#{sorteioFace.pojoSelecionado.acumulado}">
					<f:selectItem id="itemSim" itemLabel="Sim" itemValue="SIM" />
					<f:selectItem id="itemNao" itemLabel="Não" itemValue="NÃO" />
				</h:selectOneRadio>
				<h:message id="avisoAcumulado" for="acumulado" styleClass="AVISO" />

				<h:outputText value="" />
				<h:outputText value="" />
				<h:commandButton action="#{sorteioFace.salvar}" value="Salvar">
					<f:ajax execute="@form" render=":formulario :listagem :alertas" />
				</h:commandButton>
			</h:panelGrid>
		</h:form>

		<hr />

		<h2 class="title"><h:outputText
			value="#{msg.listar} #{msg.sorteios}" /></h2>

		<h:form id="listagem">

			<p:dataTable var="item" value="#{sorteioFace.listaPojosCacheados}"
				paginator="true" rows="3" dynamic="true"
				loadingMessage="Carregando informações..."
				rendered="#{!empty sorteioFace.listaPojosCacheados}"
				headerClass="cabecalhoTabela" rowClasses="linhaPar,linhaImpar"
				firstPageLinkLabel="#{msg.primeiro}"
				previousPageLinkLabel="#{msg.anterior}"
				nextPageLinkLabel="#{msg.proximo}" lastPageLinkLabel="#{msg.ultimo}">
				<p:column>
					<f:facet name="header">
						<h:outputText value="ID" />
					</f:facet>
					<h:outputText value="#{item.id}" />
				</p:column>

				<p:column sortBy="#{item.concurso}">
					<f:facet name="header">
						<h:outputText value="Concurso" />
					</f:facet>
					<h:outputText value="#{item.concurso}" />
				</p:column>

				<p:column sortBy="#{item.dataSorteio}">
					<f:facet name="header">
						<h:outputText value="Data Sorteio" />
					</f:facet>
					<h:outputText value="#{item.dataSorteio}">
						<f:convertDateTime pattern="dd/MM/yyyy" />
					</h:outputText>
				</p:column>

				<p:column>
					<f:facet name="header">
						<h:outputText value="Acumulado?" />
					</f:facet>
					<h:outputText value="#{item.acumulado}" />
				</p:column>

				<p:column>
					<f:facet name="header">
						<h:outputText value="Estimativa Prêmio" />
					</f:facet>
					<h:outputText value="#{item.estimativaPremio}" />
				</p:column>

				<p:column>
					<f:facet name="header">
						<h:outputText value="Dezenas" />
					</f:facet>
					<h:outputText value="#{item.dezenas}" />
				</p:column>

				<p:column>
					<f:facet name="header">
						<h:outputText value="#{msg.editar}" />
					</f:facet>
					<h:commandLink>
						<f:setPropertyActionListener value="#{item}"
							target="#{sorteioFace.pojoSelecionado}" />
						<h:graphicImage style="border: 0px; align: center;"
							alt="#{msg.editar}" library="images" name="botao_editar.gif">
						</h:graphicImage>
						<f:ajax execute="@this" render=":formulario" />
					</h:commandLink>
				</p:column>
				<p:column>
					<f:facet name="header">
						<h:outputText value="#{msg.excluir}" />
					</f:facet>
					<h:commandLink action="#{sorteioFace.excluir}">
						<f:setPropertyActionListener value="#{item}"
							target="#{sorteioFace.pojoSelecionado}" />
						<h:graphicImage style="border: 0px; align: center;"
							alt="#{msg.excluir}" library="images" name="botao_remover.gif">
						</h:graphicImage>
						<f:ajax execute="@this" render=":listagem :alertas" />
					</h:commandLink>
				</p:column>

			</p:dataTable>

		</h:form> <h:panelGrid columns="3" cellpadding="5" id="botoes">
			<h:commandButton value="Export as Excel">
				<p:dataExporter type="xls" target="idTabela" fileName="sorteios.xls" />
			</h:commandButton>
			<h:commandButton value="Export as PDF">
				<p:dataExporter type="pdf" target="idTabela" fileName="sorteios.dpf" />
			</h:commandButton>
			<h:commandButton value="Export as PDF page only">
				<p:dataExporter type="pdf" target="idTabela" fileName="sorteios.dpf"
					pageOnly="true" />
			</h:commandButton>
		</h:panelGrid></div>
		</div>
		</div>
	</ui:define>
</ui:composition>